import UserSessionService from "@/service/UserSessionService"
import ActionService from "@/service/ActionService"

const DefaultMessageHandler = {
    error(err, reference) {
        let message = err.message ? err.message : JSON.stringify(err);
        if (reference) {
            reference.$message.error(message);
        } else {
            alert(message);
        }
        if (err.code && (err.code.endsWith('USER_AUTH_ACCESS_DEFINED'))) {
            setTimeout(() => {
                UserSessionService.removeToken();
                ActionService.saveAction('user')
                location.reload()
            }, 2000);
        }
    },
    warning(warn, reference) {
        let message = warn.message ? warn.message : JSON.stringify(warn);
        if (reference) {
            reference.$message.warning(message);
        } else {
            alert(message);
        }
    }
}

export default DefaultMessageHandler